<?php

namespace CNEPAdmin\Controller;

use CNEPAdmin\Controller\CommonController;

class UploadController extends CommonController {

    protected $_modelName = "Upload";
    protected $_pathArr = array(
        "Public/slideImg/","Public/shopImg/","Public/pic/", "Public/goods/","Editor/upload/","Public/Article/"
    );

    public function index() {
        
    }

    public function uploadImg() {
        $pathType = intval(I("get.pathType",4));
        //dump($_FILES);
        if ($pathType==4){  //兼容编辑器
        	$filesName='upfile';
        }
        else{
        	$filesName='file';
        }
        
        $uploadArr = D("Upload")->imgApi($_FILES[$filesName], $this->_pathArr[$pathType]);
        
        /* if ($uploadArr['result']) {
        	//dump(".".str_replace(basename($uploadArr['path']), "", $uploadArr['path']));exit;
            // 生成缩略图
            $uploadArr['thumb'] = D("Upload")->imgThumbApi('.' . $uploadArr['path'],".".str_replace(basename($uploadArr['path']), "", $uploadArr['path']));
        } */
		
        if($pathType==4){
        	if ($uploadArr['result']){
        		echo json_encode(
        				[
        						'state'=>'SUCCESS',
        						'url'=>$uploadArr['path'],
        						'name'=>basename($uploadArr['path']),
        						'originalName'=>$_FILES[$filesName]['name'],
        						'size'=>basename($_FILES[$filesName]['size']),
        						"type"=> ".jpg"
        						
        				]);
        	}
        	else{
        		$this->ajaxReturn($uploadArr);
        	}
        }
        else{
        	$this->ajaxReturn($uploadArr);
        }
    }

    protected function setCode() {
        $this->_code = "Upload";
    }

}
